function print_popup(url) { 
	window.open(url,'Print', 'width=650, height=300 ,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=10,left=100'); 
}

function open_popup (url, width, height, name) {
	if(!name) name='Popup';
	window.open(url, name, 'width='+width+',height='+height+', menubar=no, scrollbars=yes, toolbar=no, location=no, directories=no, resizable=yes, top=100, left=100');
}

//exbcode javacript
var D=document;

function getSelectionInput(F) {
	return (D.selection?D.selection.createRange().text:F.value.substring(F.selectionEnd||0,F.selectionStart||0))
}

var p=document;
function exbcode_URL (u, d, what, p){
	add_content("[url="+((u=prompt("URL","http://"))?u:"")+"]"+((s=getSelectionInput(what))?s:((d=prompt("Anchor",""))?d:""))+"[/url]", what, p)
}

function exbcode_URLS (u, d, what, p){
	add_content("[urls="+((u=prompt("URL","http://"))?u:"")+"]"+((s=getSelectionInput(what))?s:((d=prompt("Anchor",""))?d:""))+"[/urls]", what, p)
}

function exbcode_B (what, p){
	add_content("[b]"+(getSelectionInput(what)?getSelectionInput(what):"")+"[/b]", what, p)
}

function exbcode_U (what, p){
	add_content("[u]"+(getSelectionInput(what)?getSelectionInput(what):"")+"[/u]", what, p)
}

function exbcode_I (what, p){
	add_content("[i]"+(getSelectionInput(what)?getSelectionInput(what):"")+"[/i]", what, p)
}

function exbcode_SIZE (what, size, p){
	add_content("[size="+((size=prompt("Size","14"))?size:"14")+"]"+((s=getSelectionInput(what))?s:"")+"[/size]", what, p);
}

function exbcode_CODE(what, code, p){
	add_content("[code="+((code=prompt("Code language","html"))?code:"html")+"]"+((s=getSelectionInput(what))?s:"")+"[/code]", what, p);
}

function exbcode_COLOR(what, color, p){
	add_content("[color="+((color=prompt("Color","red"))?color:"red")+"]"+((s=getSelectionInput(what))?s:"")+"[/color]", what, p);
}

function exbcode_QUOTE(what, user, p){
	add_content("[quote]"+((s=getSelectionInput(what))?s:"")+"[/quote]", what, p);
}

function exbcode_IMGA (what, align, p){
	add_content("[img="+((align=prompt("Align (left|right|center)","left"))?align:"left")+"]"+((s=getSelectionInput(what))?s:((d=prompt("Image source:","http://"))?d:"http://"))+"[/img]", what, p);
}

function exbcode_IMG (what, p){
	add_content("[img]"+((s=getSelectionInput(what))?s:((d=prompt("Image source:","http://"))?d:"http://"))+"[/img]", what, p);
}

function exbcode_ALIGN (what, align, p){
	add_content("[align="+((align=prompt("Align (left|right|center)","left"))?align:"left")+"]"+((s=getSelectionInput(what))?s:"")+"[/align]", what, p);
}

function exbcode_LIST (what, align, p){
	add_content("[list]"+((s=getSelectionInput(what))?s:"")+"[/list]", what, p);
}
//exbcode end

function add_content(txt, what, p){
	myQuery = what || document._form.text;
	myParent = p || document;

	//IE/Opera support
	if (myParent.selection) {
		myQuery.focus();
		sel = myParent.selection.createRange();
		sel.text = txt;
	}
	//MOZILLA/NETSCAPE support
	else if (myQuery.selectionStart || myQuery.selectionStart == "0") {
		var	myTop = myQuery.scrollTop;
		var startPos = myQuery.selectionStart;
		var endPos = myQuery.selectionEnd;
		var chaineSql = myQuery.value;

		myQuery.value = chaineSql.substring(0, startPos) + txt + chaineSql.substring(endPos, chaineSql.length);
		sPos = startPos+(txt.length);
		myQuery.selectionStart = sPos; 
		myQuery.selectionEnd = sPos;
		myQuery.scrollTop=myTop;
	}
	else {
		myQuery.value += txt;
	}


}

function quoteSelection(author, what) {
	var txt = '';

	if (window.getSelection)
		txt = window.getSelection();
	else if (document.getSelection)
		txt = document.getSelection();
	else if (document.selection)
		txt = document.selection.createRange().text;

	if(txt != '') {
		theSelection='[quote='+author+']' + txt + '[/quote]';
		add_content(theSelection, what);	
	}
}

function deselect_all(id) {
	count = document.getElementById(id).length;
	for (i=0; i < count; i++)  document.getElementById(id).options[i].selected = 0;

}

function showhide(id, expand, collapse) {
	sw = document.getElementById( 'switch_'+id );
	chngds( 'multi_'+id );

	if(sw.innerHTML.indexOf(collapse) != -1)
	{
		sw.innerHTML = '<img src="'+expand+'" alt="" />';
	} else {
		sw.innerHTML = '<img src="'+collapse+'" alt="" />';
	}
}

function chngds(id) {
	var style = document.getElementById(id).style;
	style.display = style.display == "none"? "inline" : "none";
}

function mail (prefix, suffix) {
	document.location.href='mailto:' + prefix + '@' + suffix;
}


function screenWH (what) {
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
		screenW = screen.width;
		screenH = screen.height;
	}
	else if (navigator.appName == "Netscape"  && parseInt(navigator.appVersion)==3   && navigator.javaEnabled()) {
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}

	if(what=='H')
		return screenH;
	else
		return screenW;
}

var maxW=0;
	function scaleImage(im, maxWidth, maxHeight) {
		if(!maxWidth)
			var maxWidth=500;
		if(!maxHeight)
			var maxHeight=0;

		maxW=maxWidth;

		if (typeof im.naturalWidth == 'undefined') {
			im.naturalWidth = im.width;
			im.naturalHeight = im.height;
		}

		if(maxHeight<=0) {
			if (im.naturalWidth > maxWidth) {
				im.width = maxWidth;
				im.style.maxWidth = im.naturalWidth + 'px';
				im.onclick = unscaleImage;
			}
		}
		else {
			if (im.naturalHeight > maxHeight) {
				im.height = maxHeight;
				im.style.maxHeight = im.naturalHeight + 'px';
				im.onclick = unscaleImage;
			}      
		}
	}

function unscaleImage() {
	if (this.width == maxW) {
		this.width = this.naturalWidth;
		this.style.borderWidth = '0px';
	}
	else {
		this.width = maxW;
		this.style.borderWidth = '1px';
	}
}

//select box
var currSelect=new Array(new Array(), new Array(), new Array(), new Array());
var defaultSelected=new Array();
function findInSelect(what, where, iter){
	if(currSelect[iter].length==0) {
		defaultSelected[iter]=where.selectedIndex;
		x=0;
		y=0;
		for (i=0;i<where.length;i++) {
			currSelect[iter][x]=where.options[i];

			if(where.options[i].text.toLowerCase().indexOf(what.toLowerCase())=='-1'){
				where.options[i] = null;
				i--;
				y++;
			} else { if(what) where.selectedIndex=0; }

			x++;
		}
		/*if there is no options to display, reset select*/
		if(y==x) resetSelect(where, iter);

	} else {
		resetSelect(where, iter);
		findInSelect(what, where, iter);
	}
}

//select box
function resetSelect(where, iter){

	if(currSelect[iter].length>0) {
		for (i=0; i<where.length;)	where.options[i] = null;
		for (i=0; i<currSelect[iter].length;i++) where.options[i] = new Option(currSelect[iter][i].text, currSelect[iter][i].value);
		where.selectedIndex=defaultSelected[iter];

		currSelect[iter]=new Array();
	}

	return true;
}

//change classes dynamicly
function setClass(what, className) {
	if(navigator.appName=='Microsoft Internet Explorer') 
		what.setAttribute('className', className);
	else //firefox, opera...
		what.setAttribute('class', className);
}

//check all checkbox items
function checkAll (id) {
	var el = document.getElementById(id);
	for (var i = 0; i < el.elements.length; i++)
		el.elements[i].checked = !el.elements[i].checked;
}

//disable button
function disableIt(id) {
	if(document.getElementById(id).disabled==false) document.getElementById(id).disabled = true;
	else document.getElementById(id).disabled = false;
}	

//setting a cookie
function setCookie(name, value, expire) {
	if(document.cookie) {
		document.cookie = name + "=" + escape(value) + ((expire==null)?"" : ("; expires=" + expire.toGMTString()));
		return true;
	} else return false;
}

//getting cookie value
function getCookie(name) {
	if (document.cookie!="") { //2
		var toCookie=document.cookie.split("; "); //3
		for (i=0; i<toCookie.length; i++) { //4
			 var nameCookie=toCookie[i].split("=")[0]; //5
			 var valueCookie=toCookie[i].split("=")[1]; //6
			 if (nameCookie==name) return unescape(valueCookie); //7
		}
	}
	
	return false;
}
